package com.per.mybootall.test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/1/19
 * Time: 13:53
 * Description:测试ThreadLocal【每一个线程都是独立的存储空间】
 */
public class test09 {
private static ThreadLocal<List> threadLocal=new ThreadLocal();
  public static void main(String[] args) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        threadLocal.set(new ArrayList(){{add("a");add("b");add("c");}});
        System.out.println("线程一:"+threadLocal.get());
        threadLocal.remove();
        System.out.println("线程一删除后:"+threadLocal.get());
      }
    }).start();


    new Thread(new Runnable() {
      @Override
      public void run() {
        threadLocal.set(new ArrayList(){{add("1");add("2");add("3");}});
        System.out.println("线程二:"+threadLocal.get());
      }
    }).start();
  }
}
